package com.itheima.entity;

import java.awt.*;
import java.awt.image.BufferedImage;

public class FlyingObject {
    BufferedImage img;
    protected int x;
    protected int y;
    protected int width;
    protected int hight;
    protected int speed;

    public FlyingObject() {
    }

    public FlyingObject(BufferedImage img, int x, int y, int width, int hight) {
        this.img = img;
        this.x = x;
        this.y = y;
        this.width = width;
        this.hight = hight;
    }

    public BufferedImage getImg() {
        return img;
    }

    public void setImg(BufferedImage img) {
        this.img = img;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHight() {
        return hight;
    }

    public void setHight(int hight) {
        this.hight = hight;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public void draw(Graphics g){
        g.drawImage(img,x,y,width,hight,null);
    }

    /*
    *   碰撞检测方法
    *   如果为true表示碰撞到了
    * */
    public boolean collide(FlyingObject flyingObject){
        boolean b=flyingObject.getX()+flyingObject.getWidth()>this.x&&this.x+this.hight>flyingObject.getX()&&
                flyingObject.getY()+flyingObject.getHight()>this.y&&this.y+this.hight>flyingObject.getY();

        return b;
    }
}
